package core.process.pack;

import core.rb.PB;
import core.rb.r.Pol;
import core.sb.SB;
import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class PostPack extends Thread{
    private double [][] posts;
    protected PB pIn;
    protected IndelData pOut;
    protected final CountDownLatch cdl;
    public PostPack(CountDownLatch cdl, PB packin, double [][] posts){
        this.posts = posts;
        this.pIn = packin;
        this.cdl = cdl;
        this.start();
    }

    public void run(){
        setPosts();
        cdl.countDown();
    }

    private void setPosts() {
        for(int r=0; r<pIn.getSize();r++){
            ArrayList <Pol> pols = pIn.getRead(r).getPols();
            for (int p = 0; p < pols.size(); p++) {
                if (pols.get(p).isMis()){
                    if(pols.get(p).getChar() == SB.NUCS[0]){pols.get(p).setPost(posts[0][pols.get(p).getTLoc()]);}
                    else if(pols.get(p).getChar() == SB.NUCS[1]){pols.get(p).setPost(posts[1][pols.get(p).getTLoc()]);}
                    else if(pols.get(p).getChar() == SB.NUCS[2]){pols.get(p).setPost(posts[2][pols.get(p).getTLoc()]);}
                    else if(pols.get(p).getChar() == SB.NUCS[3]){pols.get(p).setPost(posts[3][pols.get(p).getTLoc()]);}
                    else{pols.get(p).setPost(0.00);}
                }
            }
        }
    }
}